package org.epic.perleditor.templates.perl;

import java.util.Comparator;

public class PerlCompletionProposalComparator implements Comparator<Object> {

    private boolean fOrderAlphabetically;

    /**
     * Constructor for CompletionProposalComparator.
     */
    public PerlCompletionProposalComparator() {
        fOrderAlphabetically= false;
    }
    
    public void setOrderAlphabetically(boolean orderAlphabetically) {
        fOrderAlphabetically= orderAlphabetically;
    }
    
    /* (non-Javadoc)
     * @see Comparator#compare(Object, Object)
     */
    public int compare(Object o1, Object o2) {
        IPerlCompletionProposal c1= (IPerlCompletionProposal) o1;
        IPerlCompletionProposal c2= (IPerlCompletionProposal) o2;
        if (!fOrderAlphabetically) {
            int relevanceDif= c2.getRelevance() - c1.getRelevance();
            if (relevanceDif != 0) {
                return relevanceDif;
            }
        }
        return c1.getDisplayString().compareToIgnoreCase(c2.getDisplayString());
    }	
    
}
